package homework;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Method;

public class LoadXlass extends ClassLoader {
    public static void main(String[] args) throws Exception {
        File file = new File("Hello.xlass");
        FileInputStream fileInputStream = new FileInputStream(file);
        int available = fileInputStream.available();
        System.out.println("available = " + available);
        byte[] buffer = new byte[available];
        fileInputStream.read(buffer);
        for (int i = 0; i < buffer.length; i++) {
            buffer[i] = (byte) (255 - buffer[i]);
            System.out.print(buffer[i] + "\t");
            if ((i+1)%10==0){
                System.out.println();
            }
        }
        System.out.println();
        Object hello = new LoadXlass().defineClass("Hello", buffer, 0, available).newInstance();
        hello.getClass().getDeclaredMethod("hello").invoke(hello);
    }


}
